/*********************************************************************************
CREATED BY: SCOTT FIELDER 
CREATED DATE: 4/18/2011


REVISION HISTORY:
-

***********************************************************************************/




public with sharing class FB_AccessToken {
	 
	public string doFBAuthToken(string redirectURL, string code){
		FB_Graph_Settings__c fb = FB_Graph_Settings__c.getInstance();
		string endpoint = 	fb.Graph_Endpoint__c+'oauth/access_token?'+
							'client_id='+fb.FB_App_Id__c+
							'&redirect_uri=' + redirectURL+
							'&client_secret=' + fb.App_Secret__c+
							'&code=' + code;
		return endpoint;
	}
	
	
	
	/***********************************************************
	* 						TEST METHODS
	***********************************************************/
	
	static testMethod void test_doFBAuthToken(){
		
		test.startTest(); 
		
		FB_Graph_Settings__c fb = FB_Graph_Settings__c.getInstance();
		
		if(fb == null) {
            fb = new FB_Graph_Settings__c(SetupOwnerId = UserInfo.getOrganizationId());
        }
        
        fb.OF__API_Key__c = '1111111111111111111111';
        fb.OF__App_Secret__c = '11111111111111111111111';
        fb.OF__Development_Mode__c = true;
        fb.OF__FB_App_Id__c = '11111111111111';
        fb.OF__FB_Permissions_Requested__c = 'email,read_stream,publish_stream,offline_access,user_birthday';
        fb.OF__Graph_Endpoint__c = 'https://graph.facebook.com/';
        fb.OF__Host_Header__c = 'graph.facebook.com';
        
        Database.upsert(fb);
		
		string redirectURL = 'http://www.google.com';
		string code = '12345';
		FB_AccessToken cls = new FB_AccessToken();
		
		string endpoint = cls.doFBAuthToken(redirectURL, code);
		test.stopTest();
		
		system.assert(endpoint.contains(redirectURL));
		system.assert(endpoint.contains(code));
		
	}
	

}